package DAO;

import POJO.Enseignement;
import POJO.Inscription;
import POJO.Master;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Set;


public class InscriptionDAO extends DAO<Inscription>{

    public InscriptionDAO(Connection c){
        super(c);
    }

    @Override
	public Inscription find(long id) {
    	Inscription ins = null;
    	try{
    		ResultSet result = this.connexion.createStatement(
    				ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE)
    				.executeQuery("SELECT m.Master_ID, m.Nom_Master, e.Enseignement_ID, e.Intitule" +
    						" FROM Inscription i, Master m, Enseignement e" +
    						" WHERE i.Inscription_ID = " + id + " AND i.Master_ID = m.Master_ID" +
    								" AND i.Enseignement_ID = e.Enseignement_ID");
    		if (result.first()){
    			Master m = new Master (result.getLong("Master_ID"), result.getString("Nom_Master"));
    			Enseignement e = new Enseignement (result.getLong("Enseignement_ID"), result.getString("Intitule"), m);
    			ins = new Inscription (id, m, e);
    		}
    	} catch (SQLException sqle){
    		sqle.printStackTrace();
    	}
    	return ins;
	}
    
    @Override
    public boolean update(Inscription obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean delete(Inscription obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean insert(Inscription obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    @Override
    public Set<Inscription> recherche(List<String> list) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
